home *** CD-ROM | disk | FTP | other *** search
- #include "7plus.h"
- #include "globals.h"
-
- /*
- *** extract 7plus-files from log-file.
- ***
- ***
- ***
- */
-
- int extract_files (char *name, char *search)
- {
- FILE *rein, *raus;
- char string[81], destnam[13], dummi[20], *p, *q;
- int part, file, err, errn;
-
- raus = NULL;
- file = err = errn = 0;
-
- if (search)
- strlwr (search);
-
- printf ("*** 7PLUS file extractor ***\n");
-
- if ((rein = fopen (name, OPEN_READ_BINARY)) == NULL)
- {
- printf (cant, name);
- return (2);
- }
- setvbuf (rein, NULL, _IOFBF, buflen);
-
- printf ("Scanning %s for 7PLUS-files.\n\n", name);
-
- while ((p = my_fgets (string, 80, rein)) != NULL)
- {
- if (!strncmp (p, " go_", 4)) /* Beginning of a 7PLUS file. */
- {
- if (raus)
- {
- fclose (raus);
- raus = NULL;
- }
- *destnam = EOS;
- if (!strncmp (p+4, "7+.", 3)) /* It's a code file */
- {
- /* Get filename from header. Create output filename. */
- sscanf (p+7, "%d%s%s%s", &part, dummi, dummi, destnam);
- if ((q = strrchr (destnam, '.')) != NULL)
- *q = EOS;
- destnam[8] = EOS;
- if (strstr (p, "of 001"))
- sprintf (dummi, ".7pl");
- else
- sprintf (dummi, ".p%02x", part);
- strcat (destnam, dummi);
- }
- /* OK, it's an ERR or COR file. */
- if (!strncmp (p+4, "text.", 5) &&
- (strstr (p, ".ERR") || strstr (p, ".COR")))
- sscanf (p+10, "%12s", destnam);
- strlwr (destnam);
-
- err = 0;
- if (strstr (p, ".ERR"))
- err = 1;
-
- if (search && *destnam && !strstr (destnam, search))
- {
- printf ("Not extracted: %s\n", destnam);
- *destnam = EOS;
- }
- if (*destnam) /* Open output file if 7PLUS file found. */
- {
- if (err && !test_exist (destnam))
- {
- errn = 1;
- do
- {
- if ((q = strrchr (destnam, '.')) != NULL)
- *q = EOS;
- sprintf (dummi, ".e%02x", errn++);
- strcat (destnam, dummi);
- }
- while (!test_exist (destnam));
- }
-
- file++;
- printf ("Extracting %s\n", destnam);
- test_file (rein, destnam, 1, 12);
- raus = fopen (destnam, OPEN_WRITE_TEXT);
- setvbuf (raus, NULL, _IOFBF, buflen);
- }
- }
- if (raus)
- if (fprintf (raus, "%s", p) == EOF)
- {
- printf ("\007\nWrite error. Can't continue. Break.\n");
- exit (1);
- }
-
- if (!strncmp (p, " stop_", 6) && raus) /* End of file reached? */
- {
- fclose (raus);
- raus = NULL;
- }
- }
-
- printf ("\n");
-
- if (file)
- printf ("All done!\n");
- else
- if (search)
- printf ("No matching 7PLUS files found in %s.\n", name);
- else
- printf ("No 7PLUS files found in %s.\n", name);
-
- fclose (rein);
- if (raus)
- fclose (raus);
- return (0);
- }
-